1 00:00:00,490 --> 00:00:06,880 Adding our houses and fences to our lots with code is a little bit harder than a tool because the tool 2 00:00:06,880 --> 00:00:07,810 knows where to go. 3 00:00:07,810 --> 00:00:12,390 So today we're going to add stuff with code and then we'll make the purchases. 4 00:00:12,400 --> 00:00:15,940 Let's go ahead and play to see what we're going to do. 5 00:00:15,940 --> 00:00:17,680 So I have four lots there. 6 00:00:17,680 --> 00:00:24,310 I duplicated the other ones and I wrote a test script that's going to add a house and a fence to each 7 00:00:24,310 --> 00:00:26,320 lot with code, right? 8 00:00:26,320 --> 00:00:27,640 We're not buying it yet. 9 00:00:27,670 --> 00:00:29,410 We're just doing this with code. 10 00:00:29,410 --> 00:00:31,300 So we we're going to import the house. 11 00:00:31,300 --> 00:00:34,510 We're going to import the fence so we can do it right. 12 00:00:34,660 --> 00:00:35,800 That's pretty cool. 13 00:00:35,800 --> 00:00:38,860 And there's a lot of useful stuff we're going to learn in this video. 14 00:00:40,030 --> 00:00:40,330 All right. 15 00:00:40,330 --> 00:00:44,530 So in case you didn't know where I got my house and my fence, I have my Roblox studio here. 16 00:00:44,530 --> 00:00:49,990 That first starter place that they give you when you sign up, it's like mine, simtek nitros place. 17 00:00:49,990 --> 00:00:51,760 And yours will be your character's names. 18 00:00:51,760 --> 00:00:52,510 Place. 19 00:00:52,630 --> 00:00:53,920 I got that here. 20 00:00:53,920 --> 00:00:56,500 It's got a lot of cool stuff and you can use it, right? 21 00:00:56,500 --> 00:01:00,890 You got beds, you got doors and you got building stuff. 22 00:01:01,220 --> 00:01:04,910 I saved off this model right here. 23 00:01:04,910 --> 00:01:11,450 I just, like, clicked on it and then I right click saved a Roblox, and then it'll be in my toolbox. 24 00:01:11,450 --> 00:01:17,180 I did the same with the fence, but I modified the fence and then resaved it just so that you know. 25 00:01:17,910 --> 00:01:25,830 But you don't have to do that for this video because what I did was I uploaded that stuff to the marketplace 26 00:01:25,830 --> 00:01:28,020 under my account and I made it shareable. 27 00:01:28,020 --> 00:01:32,190 So I'll put this link in a file called URLs. 28 00:01:32,190 --> 00:01:33,450 That's in the resources. 29 00:01:33,450 --> 00:01:36,600 You can go to it or you can just type it in if you see it there. 30 00:01:36,600 --> 00:01:38,760 And this will say get model. 31 00:01:38,760 --> 00:01:41,190 You go ahead and click it, then you'll get the cabin right? 32 00:01:41,220 --> 00:01:42,630 But there's nothing special about it. 33 00:01:42,630 --> 00:01:44,190 You can get it in your place too. 34 00:01:44,220 --> 00:01:48,960 The cabin image you'll see that says images I saved off the image. 35 00:01:48,960 --> 00:01:50,860 We're going to use that for our store, right? 36 00:01:50,880 --> 00:01:52,800 We're going to have the image when we go to buy it. 37 00:01:52,800 --> 00:01:54,720 So I save that off too. 38 00:01:54,720 --> 00:01:56,160 And then we have the fence. 39 00:01:56,160 --> 00:01:59,400 I modified the fence, so you might want to just get this one. 40 00:01:59,520 --> 00:02:03,600 And then I have an image of that that I saved off for our store. 41 00:02:03,600 --> 00:02:06,930 All of these will say, get or get model, something like that. 42 00:02:07,200 --> 00:02:11,700 You go ahead and get them and then it'll be in your toolbox and you can follow along exactly in the 43 00:02:11,700 --> 00:02:12,480 video. 44 00:02:12,900 --> 00:02:14,700 Now let's get our fence. 45 00:02:14,700 --> 00:02:22,990 So if you use the URL that I put in the resource file and then you went to the website and hit get model 46 00:02:22,990 --> 00:02:27,430 for the fence, you can go to the toolbox and then get the fence. 47 00:02:27,430 --> 00:02:31,930 And the image is going to be a little bit different because I did like five different images. 48 00:02:31,930 --> 00:02:33,820 Let's go ahead and click it once. 49 00:02:34,210 --> 00:02:34,930 Boom. 50 00:02:34,930 --> 00:02:37,750 And this is going to be like way over there because. 51 00:02:38,970 --> 00:02:39,660 You didn't make it. 52 00:02:39,660 --> 00:02:40,350 But I did make it. 53 00:02:40,350 --> 00:02:41,190 And I made it right here. 54 00:02:41,190 --> 00:02:42,450 So I was going to be very close. 55 00:02:42,480 --> 00:02:43,380 That's all right. 56 00:02:43,410 --> 00:02:46,520 Just click on your fence and then drag it into place. 57 00:02:46,530 --> 00:02:52,020 You may have to rotate it a little bit, depending on the orientation of your lot. 58 00:02:53,190 --> 00:02:54,210 Is that good enough? 59 00:02:56,170 --> 00:02:56,880 That's good enough. 60 00:02:56,890 --> 00:02:58,600 I'll move it if I need to. 61 00:02:58,900 --> 00:02:59,200 All right. 62 00:02:59,200 --> 00:03:02,590 So we got our fence in place or somewhat in place? 63 00:03:07,700 --> 00:03:10,790 And we're going to need an anchor point for our fence. 64 00:03:10,790 --> 00:03:15,770 So unfortunately, everything here is called part. 65 00:03:15,860 --> 00:03:17,180 You know what I'm going to do? 66 00:03:18,720 --> 00:03:21,560 I'm just going to grab all these parts in this fence. 67 00:03:21,570 --> 00:03:23,630 I'm going to make it into like a submodel. 68 00:03:24,240 --> 00:03:27,480 I'll just right click and then group as model. 69 00:03:27,600 --> 00:03:31,770 And that way I don't have to worry about all those parts because in the fence I'm going to hit the plus 70 00:03:31,770 --> 00:03:36,630 sign and then I'm going to add a part and I want to be able to find it. 71 00:03:36,630 --> 00:03:37,570 It's right here. 72 00:03:37,590 --> 00:03:40,950 I'm going to call that fence anchor fence. 73 00:03:40,950 --> 00:03:42,180 Let me move my mouse 74 00:03:44,460 --> 00:03:45,340 core. 75 00:03:46,440 --> 00:03:46,860 All right. 76 00:03:46,860 --> 00:03:51,540 And like the lot anchor, we are going to need to know the front. 77 00:03:51,570 --> 00:03:53,340 The front is pointing to the left. 78 00:03:53,340 --> 00:03:55,230 I know, because that's the Z axis. 79 00:03:55,230 --> 00:03:59,250 And the default is to add it to the negative facing down the negative Z axis. 80 00:03:59,250 --> 00:04:00,950 But let's just be sure. 81 00:04:00,960 --> 00:04:02,400 Let's add a decal. 82 00:04:02,430 --> 00:04:05,430 The decal will default to the front of the part. 83 00:04:05,430 --> 00:04:07,200 So it is facing the left. 84 00:04:07,230 --> 00:04:14,730 We'll hit the fence anchor, we'll hit the rotate, go ahead and change the orientation of that part 85 00:04:14,730 --> 00:04:17,070 so that it's facing the way we want for front. 86 00:04:17,880 --> 00:04:19,330 And now on my fence. 87 00:04:19,330 --> 00:04:22,180 Anchor I'm going to make it. 88 00:04:23,230 --> 00:04:25,940 In the same position as my lot. 89 00:04:25,960 --> 00:04:29,250 Anchor I'm just going to line them up with the code. 90 00:04:29,260 --> 00:04:35,140 So let me go to my lot anchor and I'm going to get the position. 91 00:04:36,490 --> 00:04:37,450 If I can find it. 92 00:04:37,450 --> 00:04:38,320 There it is. 93 00:04:38,530 --> 00:04:43,840 Position under the C frame control C go to my fence. 94 00:04:43,840 --> 00:04:47,890 Anchor control V voila. 95 00:04:47,890 --> 00:04:51,470 And we will make sure that it's still facing front. 96 00:04:51,490 --> 00:04:52,720 It is right. 97 00:04:52,720 --> 00:04:55,570 It shouldn't change the orientation, just the position. 98 00:04:55,750 --> 00:04:56,080 All right. 99 00:04:56,110 --> 00:04:57,970 Now we need to anchor the anchor. 100 00:04:57,970 --> 00:05:03,400 So with the fence anchor selected in my fence model, I'm going to go down to. 101 00:05:04,700 --> 00:05:10,430 Anchored and then in turn can collide off so they don't interfere with each other in the game and we 102 00:05:10,430 --> 00:05:11,540 don't trip over it. 103 00:05:11,540 --> 00:05:13,340 And I'm going to make it invisible. 104 00:05:13,340 --> 00:05:17,990 So I'm going to go up to transparency, make a one. 105 00:05:18,530 --> 00:05:19,220 Cool. 106 00:05:19,220 --> 00:05:21,530 Now I got to get this fence model. 107 00:05:22,240 --> 00:05:24,920 And then I'm going to go down to primary part. 108 00:05:25,000 --> 00:05:28,920 Click that and I'm going to click Fence Anchor. 109 00:05:28,930 --> 00:05:31,540 That's going to be my primary part for my fence. 110 00:05:32,330 --> 00:05:38,650 Now let's grab our fence and I'm going to drag it down to I think I'll put it in server storage. 111 00:05:38,660 --> 00:05:42,800 This will work in replicated storage or server storage. 112 00:05:42,800 --> 00:05:47,480 But because it's fences and buildings and stuff like that, I think I'm going to go with server storage. 113 00:05:47,690 --> 00:05:51,110 Let's get a script now. 114 00:05:51,730 --> 00:05:53,710 Server script service. 115 00:05:53,980 --> 00:05:55,270 What do we have in there? 116 00:05:55,810 --> 00:05:58,030 I have my game manager, my property manager. 117 00:05:58,060 --> 00:05:59,380 We're going to add another script. 118 00:05:59,410 --> 00:06:02,380 Hit the plus sign script. 119 00:06:02,410 --> 00:06:03,400 A regular one. 120 00:06:03,400 --> 00:06:06,520 Not module, not local regular script. 121 00:06:06,520 --> 00:06:09,040 And then let's call this property test. 122 00:06:09,400 --> 00:06:11,980 Property test. 123 00:06:12,250 --> 00:06:13,600 That's good enough. 124 00:06:13,750 --> 00:06:16,330 We'll make this a little bigger so you can see it. 125 00:06:16,660 --> 00:06:20,980 Now we're going to get a reference to our server storage for our fence. 126 00:06:20,980 --> 00:06:29,380 So I'm going to say local SF for server storage game, get service server storage. 127 00:06:30,310 --> 00:06:32,760 Let's make a variable for our fence. 128 00:06:32,820 --> 00:06:34,870 Let's say local fence. 129 00:06:34,870 --> 00:06:36,370 And this is the template. 130 00:06:36,400 --> 00:06:39,430 We're going to clone the template over and over for all the different lots. 131 00:06:39,430 --> 00:06:45,460 So fence temp SS, wait for child fence. 132 00:06:46,480 --> 00:06:48,880 We'll do a wait statement so I can see it happen. 133 00:06:48,970 --> 00:06:51,740 So the game will start up and I'll be in the world. 134 00:06:51,740 --> 00:06:55,670 Then I'll do a print statement so that I know that the wait is over. 135 00:06:55,700 --> 00:06:58,850 The wait is over. 136 00:06:59,210 --> 00:07:02,900 And then we'll do a for loop for all of our different properties. 137 00:07:02,900 --> 00:07:07,040 We're going to add a couple properties and we're going to orient them funny just to make sure the fence 138 00:07:07,040 --> 00:07:08,780 lands in the right place. 139 00:07:08,780 --> 00:07:18,470 So let's do for I and V in pairs workspace dot lots and we'll get children. 140 00:07:18,470 --> 00:07:21,830 So that's all the different places do. 141 00:07:21,920 --> 00:07:24,260 I don't know why that red keeps popping up. 142 00:07:24,500 --> 00:07:25,190 There we go. 143 00:07:25,230 --> 00:07:26,090 Went away. 144 00:07:26,810 --> 00:07:29,990 Let's make a clone of the fence temp. 145 00:07:29,990 --> 00:07:37,700 So I'm going to say local fence equals fence, temp, colon, clone. 146 00:07:38,510 --> 00:07:46,670 And then we'll make the fence temps parent equal V, which is the lot. 147 00:07:46,700 --> 00:07:47,030 Right? 148 00:07:47,030 --> 00:07:49,550 So I is going to be one, two, three, four. 149 00:07:49,580 --> 00:07:53,200 V is going to be the different lots that is in lots. 150 00:07:53,210 --> 00:07:53,460 Right. 151 00:07:53,480 --> 00:07:58,010 So the the player lots these that's a V, right. 152 00:07:58,070 --> 00:07:59,780 So that's the parent. 153 00:07:59,780 --> 00:08:05,240 And then I need the anchor of the lot. 154 00:08:05,270 --> 00:08:08,060 So V dot anchor. 155 00:08:09,200 --> 00:08:10,630 Yep, we call that anchor. 156 00:08:10,640 --> 00:08:11,660 Okay good. 157 00:08:12,890 --> 00:08:15,350 And now this is new, right? 158 00:08:15,350 --> 00:08:22,670 And I used to use set primary part C frame, but now they're recommending we use the get pivot. 159 00:08:22,670 --> 00:08:29,780 So I'm going to say pivot equals anchor colon, get pivot. 160 00:08:29,780 --> 00:08:32,960 So it gets C frame information. 161 00:08:34,370 --> 00:08:36,770 And I don't even think we have to do a move to. 162 00:08:36,770 --> 00:08:38,300 I think that's going to be sufficient. 163 00:08:38,330 --> 00:08:39,740 We'll find out a minute. 164 00:08:40,520 --> 00:08:47,870 Let's get our fence now and we're going to say pivot to pivot. 165 00:08:48,140 --> 00:08:53,300 So we're going to use the anchor of the lot and then the fence. 166 00:08:53,300 --> 00:08:57,010 The primary part is the anchor point. 167 00:08:57,020 --> 00:09:02,810 The anchor points pivoted in the same direction, same location, same direction as our fence. 168 00:09:02,840 --> 00:09:06,410 We should have it plopped right down there in the lots. 169 00:09:06,410 --> 00:09:11,510 So one of these isn't very good because we we lined up our lot. 170 00:09:11,540 --> 00:09:13,250 Let's go to player lot. 171 00:09:14,530 --> 00:09:19,270 Home collisions are off, so I'll do a control D to duplicate it. 172 00:09:20,840 --> 00:09:26,840 Let's move that out and then let's just rotate it so that it's kind of funny rotation, right? 173 00:09:26,930 --> 00:09:28,970 Maybe do another control D. 174 00:09:33,040 --> 00:09:36,700 Oh, we get another lot here and we don't have to position them good. 175 00:09:36,700 --> 00:09:40,270 We just want to make sure that things are different. 176 00:09:41,400 --> 00:09:42,390 We're going to delete them. 177 00:09:42,390 --> 00:09:44,820 We're going to delete them after this because we're not done this a lot. 178 00:09:44,850 --> 00:09:46,950 But I want to see the fences appear. 179 00:09:47,340 --> 00:09:51,030 Oh, let's go to view output window. 180 00:09:51,750 --> 00:09:53,850 And we should see something happening. 181 00:09:55,280 --> 00:09:55,760 There. 182 00:09:55,790 --> 00:09:58,850 The wait is over and we have our fences. 183 00:09:59,360 --> 00:10:00,650 That's pretty cool. 184 00:10:01,070 --> 00:10:02,780 That fence looks good. 185 00:10:03,590 --> 00:10:05,080 This fence looks good. 186 00:10:05,090 --> 00:10:06,020 It's in the. 187 00:10:06,020 --> 00:10:08,480 The openings in line with the for sale sign. 188 00:10:08,510 --> 00:10:09,680 That looks good. 189 00:10:09,680 --> 00:10:11,720 So we plop those fences down. 190 00:10:11,720 --> 00:10:15,020 They're perfectly on our lots with code. 191 00:10:15,020 --> 00:10:18,640 So maybe as an exercise, you could try it with the cabin. 192 00:10:18,650 --> 00:10:20,810 I will do it in the next video, though. 193 00:10:20,810 --> 00:10:25,370 But you might want to play around with it and see if you can get that working yourself.